Helper Functions for Caching Documentation
This code provides helper functions and structures to manage various caches in the application, aiming to optimize performance by reducing database reads.
Constants
const (
SUMMARY_NO_SCHEDULE = "NoSchedule"
SUMMARY_NO_SHIFT = "NoShift"
SUMMARY_CANNOT_COMPUTE = "CannotCompute"
SUMMARY_INCOMPLETE = "Incomplete" // incomplete scans
SUMMARY_DAY_NO_WORK = "NoWork"
SUMMARY_DAY_WORK = "Work"
DEFAULT_DATE_RANGE = 30
DEFAULT_DAYS_IN_YEAR = 365
PRINT_DEBUG = true
)
SUMMARY_NO_SCHEDULE,SUMMARY_NO_SHIFT,SUMMARY_CANNOT_COMPUTE,SUMMARY_INCOMPLETE: Constants for summary statuses.SUMMARY_DAY_NO_WORK,SUMMARY_DAY_WORK: Constants for day statuses.DEFAULT_DATE_RANGE: Default date range for caching.DEFAULT_DAYS_IN_YEAR: Default number of days in a year.PRINT_DEBUG: Flag to enable or disable debug printing.
AllCacheStruct struct
type AllCacheStruct struct {
CompanyID string
Start string
End string
AutoShiftRule string
AppUser *AppUsers
Users *LocalUsers
Shifts *LocalShifts
Scans *LocalScanLog
Schedules *LocalSchedule
CalendarSchedules *LocalCalendarSchedule
Holidays *LocalCalendarHoliday
Leaves *LocalLeaves
Summaries *LocalSummaries
ScanRequests *LocalScanRequest
Settings *LocalSetting
}
CompanyID string: The company ID for which data is cached.Start string: The start date of the cached range.End string: The end date of the cached range.AutoShiftRule string: The auto shift rule.AppUser *AppUsers: Cache for application users.Users *LocalUsers: Cache for user profiles.Shifts *LocalShifts: Cache for shifts.Scans *LocalScanLog: Cache for scan logs.Schedules *LocalSchedule: Cache for schedules.CalendarSchedules *LocalCalendarSchedule: Cache for calendar schedules.Holidays *LocalCalendarHoliday: Cache for holidays.Leaves *LocalLeaves: Cache for leaves.Summaries *LocalSummaries: Cache for summaries.ScanRequests *LocalScanRequest: Cache for scan requests.Settings *LocalSetting: Cache for settings.
Functions
CalendarSchedulesEmpty() bool
Checks if the calendar schedules cache is empty.
SummariesEmpty() bool
Checks if the summaries cache is empty.
IsCacheNeedRefresh(companyID, start, end string) bool
Checks if the cache needs to be refreshed based on the company ID and date range.